package com.foreknow.demo12;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Student implements Comparable<Student> {
    private int sno;
    private String name;

    public Student() {

    }

    public Student(int sno,String name){
        this.sno = sno;
        this.name = name;
    }

    public int getSno() {
        return sno;
    }

    public void setSno(int sno) {
        this.sno = sno;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();
        Student s1 = new Student(1001,"赵四1");
        Student s2 = new Student(1002,"赵四2");
        Student s3 = new Student(1003,"赵四3");
        Student s4 = new Student(1004,"赵四4");
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);

        for (Student s:list){
            System.out.println(s.getSno()+"-------"+s.getName());
        }

        //根据编号排序
        Collections.sort(list);
        System.out.println("_________________");
        for (Student s:list){
            System.out.println(s.getSno()+"-----");
        }
    }

    @Override
    public int compareTo(Student o) {
        if(this.sno < o.sno) {
            return -1;
        }else if(this.sno == o.sno) {
            return 0;
        }else {
            return 1;
        }
    }
}
